package and.bumper.close.activities;

import and.bumper.close.R;
import and.bumper.close.listener.ShakeEventListener;
import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.Toast;

public class ShakerTestActivity extends Activity{
	
	 private SensorManager mSensorManager;

	 private ShakeEventListener mSensorListener;
	
	 public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        mSensorListener = new ShakeEventListener();
	        mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
	        mSensorManager.registerListener(mSensorListener,
	            mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
	            SensorManager.SENSOR_DELAY_UI);


	        mSensorListener.setOnShakeListener(new ShakeEventListener.OnShakeListener() {

	          public void onShake() {
	            Toast.makeText(ShakerTestActivity.this, "Shake!", Toast.LENGTH_SHORT).show();
	          }
	        });
	    }

	 @Override
	  protected void onResume() {
	    super.onResume();
	    mSensorManager.registerListener(mSensorListener,
	        mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
	        SensorManager.SENSOR_DELAY_UI);
	  }

	  @Override
	  protected void onStop() {
	    mSensorManager.unregisterListener(mSensorListener);
	    super.onStop();
	  }

}
